﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KeywordAuction;
using Simulation.Mechanism;

namespace Simulation
{
    public class AuctionFactoryForChapter4GSP : IAuctionHostFactory
    {
        public AuctionHost Create()
        {
            var auctionHost = new AuctionHost();
            auctionHost.AuctionMechanism = new GSPAuctionMechanism();

            for (int i = 0; i < 3; i++)
            {
                var advertiser = auctionHost.CreateAdvertiser();
                auctionHost.Advertisers.Add(advertiser);
                advertiser.Tactics = new KeywordAuction.Tactics.BreadthFirstTactics();
                advertiser.Strategies.Add(new StrategyRaiseAll { });
                advertiser.Strategies.Add(new StrategyDropAll { });
                advertiser.Strategies.Add(new StrategyHoldAll());
                advertiser.Name = string.Format("Player {0}", i);
            }
            var ctrs = new List<double>();
            ctrs.Add(0.1);
            ctrs.Add(0.05);
            var adspot = KeywordAuction.Utility.AdspotFactory.Create(auctionHost, 200, 2, ctrs);
            adspot.Name = "Adspot 0";
            auctionHost.Adspots.Add(adspot);
            var random = new Random();
            double value = 30;
            foreach (var spot in auctionHost.Adspots)
            {
                foreach (var advertiser in auctionHost.Advertisers)
                {
                    var bidding = AdvertiserBidding.CreateAdvertiserBidding(advertiser, spot);
                    bidding.ExpectedRevenue = value;// random.Next(30, 100);
                    value += 20;
                    advertiser.Biddings.Add(bidding);
                    spot.Bitting.Add(bidding);
                }
            }

            return auctionHost;
        }
    }


    public class AuctionFactoryForChapter4GFP : IAuctionHostFactory
    {
        public AuctionHost Create()
        {
            var auctionHost = new AuctionHost();
            auctionHost.AuctionMechanism = new GFPAuctionMechanism();
            auctionHost.Name = "Chap4.GFP";
            for (int i = 0; i < 3; i++)
            {
                var advertiser = auctionHost.CreateAdvertiser();
                auctionHost.Advertisers.Add(advertiser);
                advertiser.Tactics = new KeywordAuction.Tactics.BreadthFirstTactics();
                advertiser.Strategies.Add(new StrategyRaiseAll { });
                advertiser.Strategies.Add(new StrategyDropAll { });
                advertiser.Strategies.Add(new StrategyHoldAll());
                advertiser.Name = string.Format("Player {0}", i);
            }
            var ctrs = new List<double>();
            ctrs.Add(0.6131);
            ctrs.Add(0.5111);
            var adspot = KeywordAuction.Utility.AdspotFactory.Create(auctionHost, 171, 2, ctrs);
            adspot.Name = "Adspot 0";
            auctionHost.Adspots.Add(adspot);
            var random = new Random();
            double value = 26;
            foreach (var spot in auctionHost.Adspots)
            {
                foreach (var advertiser in auctionHost.Advertisers)
                {
                    var bidding = AdvertiserBidding.CreateAdvertiserBidding(advertiser, spot);
                    bidding.ExpectedRevenue = value;// random.Next(30, 100);
                    if (value == 26)
                    {
                        value = 60;
                    }
                    else
                    {
                        value = 69;
                    }
                    advertiser.Biddings.Add(bidding);
                    spot.Bitting.Add(bidding);
                }
            }

            return auctionHost;
        }
    }


    public class AuctionFactoryForChapter4VCG : IAuctionHostFactory
    {
        public AuctionHost Create()
        {
            var auctionHost = new AuctionHost();
            auctionHost.AuctionMechanism = new VCGAuctionMechanism();
            auctionHost.Name = "Chap4.VCG";
            for (int i = 0; i < 3; i++)
            {
                var advertiser = auctionHost.CreateAdvertiser();
                auctionHost.Advertisers.Add(advertiser);
                advertiser.Tactics = new KeywordAuction.Tactics.BreadthFirstTactics();
                advertiser.Strategies.Add(new StrategyRaiseAll { });
                advertiser.Strategies.Add(new StrategyDropAll { });
                advertiser.Strategies.Add(new StrategyHoldAll());
                advertiser.Name = string.Format("Player {0}", i);
            }
            var ctrs = new List<double>();
            ctrs.Add(0.6131);
            ctrs.Add(0.5111);
            var adspot = KeywordAuction.Utility.AdspotFactory.Create(auctionHost, 171, 2, ctrs);
            adspot.Name = "Adspot 0";
            auctionHost.Adspots.Add(adspot);
            var random = new Random();
            double value = 26;
            foreach (var spot in auctionHost.Adspots)
            {
                foreach (var advertiser in auctionHost.Advertisers)
                {
                    var bidding = AdvertiserBidding.CreateAdvertiserBidding(advertiser, spot);
                    bidding.ExpectedRevenue = value;// random.Next(30, 100);
                    if (value == 26)
                    {
                        value = 60;
                    }
                    else
                    {
                        value = 69;
                    }
                    advertiser.Biddings.Add(bidding);
                    spot.Bitting.Add(bidding);
                }
            }

            return auctionHost;
        }
    }
    public class AuctionFactoryForChapter4LEF : IAuctionHostFactory
    {
        public AuctionHost Create()
        {
            var auctionHost = new AuctionHost();
            auctionHost.AuctionMechanism = new LEFGSPAuctionMechanism();
            auctionHost.Name = "Chap4.LEFGSP";
            for (int i = 0; i < 3; i++)
            {
                var advertiser = auctionHost.CreateAdvertiser();
                auctionHost.Advertisers.Add(advertiser);
                advertiser.Tactics = new KeywordAuction.Tactics.BreadthFirstTactics();
                advertiser.Strategies.Add(new StrategyRaiseAll { });
                advertiser.Strategies.Add(new StrategyDropAll { });
                advertiser.Strategies.Add(new StrategyHoldAll());
                advertiser.Name = string.Format("Player {0}", i);
            }
            var ctrs = new List<double>();
            ctrs.Add(0.6131);
            ctrs.Add(0.5111);
            var adspot = KeywordAuction.Utility.AdspotFactory.Create(auctionHost, 171, 2, ctrs);
            adspot.Name = "Adspot 0";
            auctionHost.Adspots.Add(adspot);
            var random = new Random();
            double value = 26;
            foreach (var spot in auctionHost.Adspots)
            {
                foreach (var advertiser in auctionHost.Advertisers)
                {
                    var bidding = AdvertiserBidding.CreateAdvertiserBidding(advertiser, spot);
                    bidding.ExpectedRevenue = value;// random.Next(30, 100);
                    if (value == 26)
                    {
                        value = 60;
                    }
                    else
                    {
                        value = 69;
                    }
                    advertiser.Biddings.Add(bidding);
                    spot.Bitting.Add(bidding);
                }
            }

            return auctionHost;
        }
    }
}
